package bishi.qianxin;

import java.util.HashSet;

/**
 * @author: 唐小尊
 * @email: 1171702529@qq.com
 * @cate: 2021/08/07 15:08
 */
public class one {
    public static void main(String[] args) {
        System.out.println(TeamNums(new int[]{1, 5, 3, 2, 4}));
    }

    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * @param height int整型一维数组 舞蹈员身高的一维数组
     * @return int整型
     */
    static HashSet<Integer> set = new HashSet<>();
    public static int TeamNums(int[] height) {
        // write code here
        int res = 0;
        for (int i = 0; i < height.length - 2; i++) {
            set.add(height[i]);
            res += dfs(height, i, 2, true);//增序
            res += dfs(height, i, 2, false);//降序
            set.remove(height[i]);
        }
        return res;
    }

    public static int dfs(int[] height, int i, int k, boolean b) {
        if (k == 0) {
            System.out.println(set);
            return 1;
        }
        int res = 0;
        int now = height[i];
        i++;
        for (; i < height.length - k + 1; i++) {
            if (height[i] > now && b) {
                set.add(height[i]);
                res += dfs(height, i, k - 1, b);
                set.remove(height[i]);
            }
            if (height[i] < now && !b) {
                set.add(height[i]);
                res += dfs(height, i, k - 1, b);
                set.remove(height[i]);
            }
        }
        return res;
    }
}
